/*  1:   */ package cn.com.dashihui.pay.ZY;
/*  2:   */ 
/*  3:   */ import java.util.ArrayList;
/*  4:   */ import java.util.Collections;
import java.util.HashMap;
/*  5:   */ import java.util.List;
/*  6:   */ import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/*  7:   */ import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;
/*  8:   */ 
/*  9:   */ public class EncryUtils
/* 10:   */ {
/* 11:   */   public static StringBuilder createLinkString(Map<String, String> params)
/* 12:   */   {
/* 13:13 */     List<String> keys = new ArrayList(params.keySet());
/* 14:14 */     Collections.sort(keys);
/* 15:   */     
/* 16:16 */     StringBuilder prestr = new StringBuilder();
/* 17:17 */     String key = "";
/* 18:18 */     String value = "";
/* 19:20 */     for (int i = 0; i < keys.size(); i++)
/* 20:   */     {
/* 21:21 */       key = (String)keys.get(i);
/* 22:22 */       value = (String)params.get(key);
/* 23:23 */       if ((!"".equals(value)) && (value != null) && (!key.equalsIgnoreCase("SIGN_STR"))) {
/* 24:26 */         prestr.append(value).append("&");
/* 25:   */       }
/* 26:   */     }
/* 27:28 */     return prestr.deleteCharAt(prestr.length() - 1);
/* 28:   */   }
/* 29:   */   
/* 30:   */   public static String sign(Map<String, String> params, String merPrivateKey)
/* 31:   */   {
/* 32:32 */     String sign = "";
/* 33:33 */     if (StringUtils.isNotEmpty(merPrivateKey)) {
/* 34:34 */       sign = RSA.sign(createLinkString(params).toString(), merPrivateKey);
/* 35:   */     }
/* 36:37 */     return sign;
/* 37:   */   }
/* 38:   */   
/* 39:   */   public static boolean checkSign(Map<String, String> params, String dowmerPublicKey)
/* 40:   */     throws Exception
/* 41:   */   {
/* 42:41 */     String sign = StringUtils.trimToEmpty((String)params.get("SIGN_STR"));
/* 43:   */     
/* 44:43 */     return RSA.checkSign(createLinkString(params).toString(), sign, dowmerPublicKey);
/* 45:   */   }
/* 45:   */   public static  Map<String,Object>  toMap(JSONObject json) {
				Map<String,Object> map = new HashMap<String,Object>();
			    map.put("result", json.get("result"));
			    map.put("msg", json.get("msg"));
			    map.put("data", JSONObject.fromObject(json.get("data")));
				return map;
			  }
			public static String JudgeIsMoblie(HttpServletRequest request) {
				String isMoblie = "1";
				String[] mobileAgents = { "iphone", "android","ipad", "phone", "mobile", "wap", "netfront", "java", "opera mobi",
						"opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod",
						"nokia", "samsung", "palmsource", "xda", "pie经纪人", "meizu", "midp", "cldc", "motorola", "foma",
						"docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos",
						"techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem",
						"wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos",
						"pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320",
						"240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac",
						"blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs",
						"kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi",
						"mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port",
						"prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem",
						"smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v",
						"voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-",
						"Googlebot-Mobile" };
				if (request.getHeader("User-Agent") != null) {
					String agent=request.getHeader("User-Agent");
					for (String mobileAgent : mobileAgents) {
						if (agent.toLowerCase().indexOf(mobileAgent) >= 0&&agent.toLowerCase().indexOf("windows nt")<=0 &&agent.toLowerCase().indexOf("macintosh")<=0) {
							isMoblie = "2";
							break;
						}
					}
				}
				return isMoblie;
			}
			/**
			 * 获取真实IP
			 * @param request 请求体
			 * @return 真实IP
			 */
			public static String getRealIp(HttpServletRequest request) {
				// 这个一般是Nginx反向代理设置的参数
			    String ip = request.getHeader("X-Real-IP");
			    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			        ip = request.getHeader("X-Forwarded-For");
			    }
			    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			        ip = request.getHeader("Proxy-Client-IP");
			    }
			    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			        ip = request.getHeader("WL-Proxy-Client-IP");
			    }
			    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			        ip = request.getRemoteAddr();
			    }
			    // 处理多IP的情况（只取第一个IP）
			    if (ip != null && ip.contains(",")) {
			        String[] ipArray = ip.split(",");
			        ip = ipArray[0];
			    }
			    if(ip.toString().equals("0:0:0:0:0:0:0:1")){
			    	ip = "127.0.0.1";
			    }
			    return ip;
			}


/* 46:   */ }


/* Location:           D:\公司项目\K00一账通\10031收银台\10031-payservice-v1.2.93.1.02.jar
 * Qualified Name:     com.ylsoft.pcore.business.service.sign.EncryUtils
 * JD-Core Version:    0.7.0.1
 */